//
//  AddHeadPhotoCell.m
//  MIDI
//
//  Created by 邵子凡 on 15/11/23.
//  Copyright © 2015年 QXSX. All rights reserved.
//

#import "AddHeadPhotoCell.h"
#import "UserDataSingleton.h"
#import "UIImageView+WebCache.h"

@interface AddHeadPhotoCell ()

@property (weak, nonatomic) IBOutlet UILabel *MIDI_ID;

@end

@implementation AddHeadPhotoCell

+(instancetype)cellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"AddHeadPhotoCell";
    
    AddHeadPhotoCell  *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"AddHeadPhotoCell" owner:nil options:nil]firstObject] ;
    }
    
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    return cell;
}

- (void)awakeFromNib {
    
    self.headImageBtn.userInteractionEnabled = NO;
    [self.headImageBtn.layer setCornerRadius:self.headImageBtn.frame.size.width/2];
    self.headImageBtn.contentMode = UIViewContentModeScaleAspectFill;
    self.headImageBtn.clipsToBounds = YES;
    
    UserDataSingleton * userdata = [UserDataSingleton shareInstance];
    if([userdata isLogin])
    {
        if(userdata.isGotSelfInfo)
        {
            [self.MIDI_ID setText:[@"Midi ID:" stringByAppendingString:userdata.midi_id]];
            NSString *icoUrl = userdata.head_img;
            if(icoUrl == nil || [icoUrl isEqual:@""])
            {
                [self.headImageBtn setImage:[UIImage imageNamed:@"ico_selfinfo_nonoe"] forState:UIControlStateNormal];
            }
            else
            {   
                UIImageView *imageView = [[UIImageView alloc] init];
                
                [imageView sd_setImageWithURL:[NSURL URLWithString:userdata.head_img] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
                 {
                     [self.headImageBtn setImage:imageView.image forState:UIControlStateNormal];
                 }];
            }
        }
    }
    
    //头像按钮点击事件
    [self.headImageBtn addTarget:self action:@selector(headImageBtn_Click) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
